package com.sq.activity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sq.common.core.domain.R;
import com.sq.common.core.domain.entity.SysUser;
import com.sq.common.utils.UserThreadLocal;
import com.sq.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sq.common.annotation.Log;
import com.sq.common.core.controller.BaseController;
import com.sq.common.core.domain.AjaxResult;
import com.sq.common.enums.BusinessType;
import com.sq.activity.domain.Reviews;
import com.sq.activity.service.IReviewsService;
import com.sq.common.utils.poi.ExcelUtil;
import com.sq.common.core.page.TableDataInfo;

/**
 * 评价Controller
 * 
 * @author shan
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/activity/reviews")
@Api(tags = "评价相关接口")
public class ReviewsController extends BaseController
{
    @Autowired
    private IReviewsService reviewsService;

    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询评价列表
     */
    @PreAuthorize("@ss.hasPermi('activity:reviews:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取评价列表")
    public TableDataInfo<List<Reviews>> list(Reviews reviews)
    {
        startPage();
        List<Reviews> list = reviewsService.selectReviewsList(reviews);
        return getDataTable(list);
    }

    /**
     * 导出评价列表
     */
    @PreAuthorize("@ss.hasPermi('activity:reviews:export')")
    @Log(title = "评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出评价列表")
    public void export(HttpServletResponse response, Reviews reviews)
    {
        List<Reviews> list = reviewsService.selectReviewsList(reviews);
        ExcelUtil<Reviews> util = new ExcelUtil<Reviews>(Reviews.class);
        util.exportExcel(response, list, "评价数据");
    }

    /**
     * 获取评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:reviews:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取评价详细信息")
    public R<Reviews> getInfo(@ApiParam(value = "评价ID", required = true)
            @PathVariable("id") Long id)
    {
        return R.ok(reviewsService.selectReviewsById(id));
    }

    /**
     * 新增评价
     */
    @PreAuthorize("@ss.hasPermi('activity:reviews:add')")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增评价")
    public AjaxResult add(@ApiParam(value = "评价实体", required = true) @RequestBody Reviews reviews)
    {
        return reviewsService.insertReviews(reviews);
    }

    /**
     * 修改评价
     */
    @PreAuthorize("@ss.hasPermi('activity:reviews:edit')")
    @Log(title = "评价", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改评价")
    public AjaxResult edit(@ApiParam(value = "评价实体", required = true) @RequestBody Reviews reviews)
    {
        return toAjax(reviewsService.updateReviews(reviews));
    }

    /**
     * 删除评价
     */
    @PreAuthorize("@ss.hasPermi('activity:reviews:remove')")
    @Log(title = "评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除评价")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids)
    {
        return toAjax(reviewsService.deleteReviewsByIds(ids));
    }


    /**
     * 获取用户
     * @return
     */
    @Log(title = "获取用户")
    @GetMapping("/getUser")
    public AjaxResult getuser()
    {
        SysUser sysUser = sysUserService.selectUserById(UserThreadLocal.getUserId());
        return AjaxResult.success(sysUser);
    }
}
